RPI3上使用java控制Bluetooth

技术经验 dingxiao 阅读数:2440 2018年7月16日 15:37

RPI3上使用java控制Bluetooth

RPI3上使用java控制Bluetooth一直是自己想实现的功能,今天在外媒java bluetooth终于让我找到了方法,现将操作过程简单记录下。RPI3使用最新debian镜像(20170302)作为操作系统,并在3.5TFT上运行系统程序。

### 1.Step 1: Enable Bluetooth on the Raspberry Pi 3 ###

  sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install piclone geany usb-modeswitch pi-bluetooth
sudo apt-get install python-pigpio python3-pigpio

2.Step 2: turn on bluetooth control mode

  sudo bluetoothctl
agent on
default-agent

3.Step 3: 安装Android蓝牙应用BlueTerm,与PI3进行蓝牙BLE通讯

  scan on
You will see the MAC Addresses of nearby devices
Discovery started
[NEW] Controller XX:YY:ZZ:AA:BB:CC #Your Pi's MAC Address
[NEW] Device DD:EE:FF:GG:HH:II #Your Android's MAC Address
To pair the phone, replace MAC Address with your own
pair DD:EE:FF:GG:HH:II
[agent] Confirm passkey 123456 (yes/no): yes
[CHG] Device DD:EE:FF:GG:HH:II Modalias: bluetooth:xxxx
[CHG] Device DD:EE:FF:GG:HH:II UUIDs
<bunch of numbers>
[CHG] Device DD:EE:FF:GG:HH:II Paired: Yes
Pairing successful
[CHG] Device DD:EE:FF:GG:HH:II Connected: No
[CHG] Device DD:EE:FF:GG:HH:II Trusted: Yes

4.Step 4: Sending and Receiving Serial Data

  sudo nano /etc/systemd/system/dbus-org.bluez.service
ExecStart=/usr/lib/bluetooth/bluetoothd -C
ExecStartPost=/usr/bin/sdptool add SP
sudo rfcomm watch hci0

5.Step 5: 通过命令连接到rfcomm0观察RPI3蓝牙BLE接收到的数据

  cat /dev/rfcomm0

   !!!需要注意的是java测试代码必须连接手机APP,并在“sudo rfcomm watch hci0”“cat /dev/rfcomm0”和指令执行之后运行。


captcha
    暂无评论